package com.infore.airsupervise.other.listener;

import android.support.v4.app.FragmentManager;

import com.infore.airsupervise.utils.DateUtil;
import com.infore.airsupervise.utils.DialogUtil;
import com.rey.material.app.DatePickerDialog;
import com.rey.material.app.DialogFragment;
import com.rey.material.app.TimePickerDialog;

import java.text.SimpleDateFormat;

/**时间选择 功能 业务实现类
 * Created by xiaotao on 2017/5/18.
 */

public class DateAndTimeBizImpl implements DateAndTimeBiz {
    @Override
    public void getDatePicker(FragmentManager fragmentManager , final DateAndTimeListener listener) {
        DialogUtil.getInstance().datePicker(new DialogUtil.OnDialogActionListener() {
            @Override
            public void onPositiveActionClicked(DialogFragment fragment) {
                DatePickerDialog dateDialog = (DatePickerDialog) fragment.getDialog();
                String date = dateDialog.getFormattedDate(new SimpleDateFormat(DateUtil.FORMAT_DATE));
                listener.getDateAndTimeString(date);
            }

            @Override
            public void onNegativeActionClicked(DialogFragment fragment) {

            }
        },0 ,0).show(fragmentManager, null);
    }

    @Override
    public void getTimePicker(FragmentManager fragmentManager , final DateAndTimeListener listener) {
        DialogUtil.getInstance().timePicker(new DialogUtil.OnDialogActionListener() {
            @Override
            public void onPositiveActionClicked(DialogFragment fragment) {
                TimePickerDialog dateDialog = (TimePickerDialog) fragment.getDialog();
                String time = dateDialog.getFormattedTime(new SimpleDateFormat(DateUtil.FORMAT_TIME));
                listener.getDateAndTimeString(time);
            }

            @Override
            public void onNegativeActionClicked(DialogFragment fragment) {

            }
        }).show(fragmentManager, null);
    }

    @Override
    public void getDateAndTimePicker(final FragmentManager fragmentManager , final DateAndTimeListener listener) {
        getDatePicker(fragmentManager, new DateAndTimeListener() {
            @Override
            public void getDateAndTimeString(final String dateAndTime) {
                getTimePicker(fragmentManager, new DateAndTimeListener() {
                    String date = dateAndTime;
                    @Override
                    public void getDateAndTimeString(String dateAndTime) {
                        listener.getDateAndTimeString(date+" "+dateAndTime);
                    }
                });
            }
        });
    }
}
